package com.monkeys.controller;

import com.monkeys.pojo.GoodsDemand;
import com.monkeys.pojo.Result;
import com.monkeys.service.GoodsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author KuangTeam
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/goods")
public class GoodsController {

    private final GoodsService goodsService;

    //选择一批货主(返回id)
    @PostMapping
    public Result<List<Integer>> getOwners(){
        List<Integer> ids = goodsService.getOwners();
        return Result.success(ids);
    }

    //创建一次订单
    @GetMapping("/create")
    public Result<GoodsDemand> createGoods(){
        GoodsDemand goodsDemand = goodsService.createGoods();
        return Result.success(goodsDemand);
    }

    //创建任意个订单
    @GetMapping("/create/{id}")
    public Result<List<GoodsDemand>> createGoodsById(@PathVariable Long id){
        List<GoodsDemand> goodsDemandList = goodsService.createGoodsById(id);
        return Result.success(goodsDemandList);
    }

    //更新订单
    @PutMapping("/update")
    public Result<Object> updateGoodsDemand(GoodsDemand goodsDemand){
        goodsService.updateGoodsDemand(goodsDemand);
        return Result.success();
    }
}
